<?php
    require "config.php";
    $dbh = dbConnect();
    try{
        $sql = "select * from diary  order by addtime DESC";
        $sth = $dbh->query($sql);
        $rows = $sth->fetchAll();
    }catch(PDOException $e){
        print('Error:'.$e->getMessage());
        die();
    }

?>

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台管理主页面</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/after-message.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
</head>

<body>
    <header>
        <div class="page-header">
            <h1>用户留言管理</h1>
        </div>
    </header>

    <article>
        <nav>
            <ul class="nav nav-tabs">
                <li role="presentation" class="active"><a href="after-message.php">留言管理</a></li>
                <li role="presentation"><a href="after-users.php">用户管理</a></li>
                <li role="presentation"><a href="after-manager.php">管理员管理</a></li>
            </ul>
        </nav>

        <div>
            <table class="table table-bordered">
                <tr>
                    <th>留言标题</th>
                    <th>留言内容</th>
                    <th>留言日期</th>
                    <th>执行操作</th>
                </tr>
                <?php foreach($rows as $row):?>
                    <tr>
                        <td><?= $row['title']?></td>
                        <td><?= $row['content']?></td>
                        <td><?= $row['addtime']?></td>
                        <td><a href="after-deleteMessage.php?id=<?= $row['id']?>">删除</a></td>
                    </tr>
                <?php endforeach;?>    
            </table>
        </div>

    </article>

</body>

</html>